import configparser

import tkinter as tk
from tkinter import *
from tkinter import ttk

config = configparser.ConfigParser()
config.read('../Config/config.ini')

ClientConfigs = ['Development', 'Debug', 'Shipping']
Platforms = ['Win64', 'Linux', 'Android', 'iOS']

def openUpdateConfig():
    from Apps.Functions.GenerateConfigFile import UpdateConfig

    root = Tk()
    root.title("Unreal Project Developer Tools ( UPDT ) - Update config")
    root.geometry("300x400")
    root.resizable(False, False)

    frame = Frame(root, padx=10, pady=10)
    frame.pack(expand=True)
    
    engine_path = config.get('EngineInfo', 'engine_path')
    EnginePath_label = ttk.Label(frame, text="Engine path")
    EnginePath_label.grid(row=1, column=1)

    EnginePath_Entry = ttk.Entry(frame, width=40)
    EnginePath_Entry.insert(0, engine_path)
    EnginePath_Entry.grid(row=2, column=1)

    project_path = config.get('ProjectInfo', 'project_path')
    project_path_label = ttk.Label(frame, text="Project path")
    project_path_label.grid(row=3, column=1)

    project_path_Entry = ttk.Entry(frame, width=40)
    project_path_Entry.insert(0, project_path)
    project_path_Entry.grid(row=4, column=1)
    
    project_name = config.get('ProjectInfo', 'project_name')
    project_name_label = ttk.Label(frame, text="Project name")
    project_name_label.grid(row=5, column=1)

    project_name_Entry = ttk.Entry(frame, width=40)
    project_name_Entry.insert(0, project_name)
    project_name_Entry.grid(row=6, column=1)

    project = config.get('ProjectInfo', 'project')
    project_label = ttk.Label(frame, text="Uproject file path")
    project_label.grid(row=7, column=1)

    project_Entry = ttk.Entry(frame, width=40)
    project_Entry.insert(0, project)
    project_Entry.grid(row=8, column=1)

    git_username = config.get('UserInfo', 'git_username')
    git_username_label = ttk.Label(frame, text="GitHub @username")
    git_username_label.grid(row=9, column=1)

    git_username_Entry = ttk.Entry(frame, width=40)
    git_username_Entry.insert(0, git_username)
    git_username_Entry.grid(row=10, column=1)

    clientconfig = config.get('BuildInfo', 'clientconfig')
    clientconfig_label = ttk.Label(frame, text="Client config")
    clientconfig_label.grid(row=11, column=1)

    clientconfig_Combobox = ttk.Combobox(frame, width=40, values=ClientConfigs)
    clientconfig_Combobox.insert(0, clientconfig)
    clientconfig_Combobox.grid(row=12, column=1)   

    platform = config.get('BuildInfo', 'platform')
    platform_label = ttk.Label(frame, text="Build platform")
    platform_label.grid(row=13, column=1)

    platform_Combobox = ttk.Combobox(frame, width=40, values=Platforms)
    platform_Combobox.insert(0, platform)
    platform_Combobox.grid(row=14, column=1)

    UpdateConfig_Button = ttk.Button(frame, text="Update", width=40, command=lambda:UpdateConfig(
        EnginePath_Entry.get(),
        project_path_Entry.get(),
        project_name_Entry.get(), 
        project_Entry.get(), 
        git_username_Entry.get(),
        clientconfig_Combobox.get(),
        platform_Combobox.get()
        )
    )
    UpdateConfig_Button.grid(row=15, column=1)
